<?php
namespace app\common\controller;

use think\Cache;
use think\Controller;
use think\Db;
use think\Session;

class HomeBase extends Controller
{

    protected function _initialize()
    {
        parent::_initialize();
        $this->getMemberStatus();

        if(!Session::get('member_info')){
            Session::set('no_login',1);
            $this->redirect(url('login/index'));
        }
    }
    
    /*检查会员的状态 一旦到期马上停止状态*/
    public function getMemberStatus () {
        $pay_info = Db::name('member_pay_log')->where(['member_id'=>Session::get('member_info.id')])->order('expire_time desc')->find();
        
        $member_info = Db::name('member')->find(Session::get('member_info.id')); 
        
        if($pay_info && $member_info['level_status']!=0){ //如果有记录 而且超过了过期时间 那么过期了
            $time = $pay_info['expire_time'];
            if(time() >$time){
                Db::name('member')->where(['id'=>Session::get('member_info.id')])->update(['pay_status'=>0,'level_status'=>0]);
            }
        }
    }

   
}